package com.aote.serialnumber;

import com.browsesoft.tools.BSCalendar;

/**
 * 根据固定的日期进行初始化
 * 
 */
public class YearInitRule implements InitRule {

	/**
	 * 编号类
	 */
	private IncreaseSerialNumber sn = null;

	public YearInitRule(IncreaseSerialNumber sn) {
		this.sn = sn;
	}

	/**
	 * 是否初始化
	 */
	public boolean isInit() {
		// 得到当前年
		int year = BSCalendar.now().getYear();
		// 得到编号上次初始化年
		int lastYear = getLastInitDate();
		if (year == lastYear) {
			return false;
		}
		return true;
	}

	private int getLastInitDate() {
		String date = (String) this.sn.getAttributes().get("date");
		BSCalendar bs = new BSCalendar(date);
		int firstYear = bs.getYear();
		return firstYear;
	}

}
